#include "asio_thread_poll.h"

AsioThreadPool::AsioThreadPool(std::size_t threadCount)
:_work(new boost::asio::io_context::work(_io_context))
{
    for (std::size_t i = 0; i < threadCount; ++i)
    {
        _threads.emplace_back(std::thread([this] { 
            _io_context.run(); 
        }));
    }
}

AsioThreadPool::~AsioThreadPool()
{
    stop();
}

AsioThreadPool::IOContext& AsioThreadPool::get_io_context()
{
    return _io_context;
}

void AsioThreadPool::stop()
{
    _work.reset();
    for (auto& thread : _threads)
    {
        thread.join();
    }
}